<html>
<head><meta charset="utf-8"><title>derive(PartialEq,Eq) in the stdlib · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/derive(PartialEq.2CEq).20in.20the.20stdlib.html">derive(PartialEq,Eq) in the stdlib</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231690417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/derive%28PartialEq%2CEq%29%20in%20the%20stdlib/near/231690417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/derive(PartialEq.2CEq).20in.20the.20stdlib.html#231690417">(Mar 24 2021 at 19:02)</a>:</h4>
<p>So, in &lt;<a href="https://internals.rust-lang.org/t/typeid-structuraleq-is-this-necessary-or-planned-to-be-useful-in-the-future/14167?u=infernodeity">https://internals.rust-lang.org/t/typeid-structuraleq-is-this-necessary-or-planned-to-be-useful-in-the-future/14167?u=infernodeity</a>&gt;. I brought up the fact that TypeId is StructuralEq in rustc's implementation, which seems to be an artifact of the implementation deriving PartialEq and Eq.  I also note an implementation of TypeId I seek to use, which solves the soundness issue with collisions, but is incompatible with derive(PartialEq,Eq). </p>
<p>Based on some discussion on the Rust Community Discord, it turns out a few more types (most notably, String),  also have these same artifacts. Currently they are not affecting the well-formedness of any code, but it is something to consider.</p>
<p>Currently, there is a semantic difference between deriving PartialEq or Eq, and providing equivalent manual implementations.  It may be a good idea for someone (and I do certainly volunteer myself in the neer future) to go through the standard library and remove the derives from places they currently are not effective (replacing them instead with manual implementations that are equivalent). I would also think it's a good idea to explicitly document which types are supposed to derive either and/or both, due to the semantic difference. Would the latter part require an RFC, or something similar? Given the fact the former is explicitly only affecting types which cannot be used in structural match, I assume that would not, but would require a crater run (please correct me if I am wrong).</p>



<a name="231696271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/derive%28PartialEq%2CEq%29%20in%20the%20stdlib/near/231696271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/derive(PartialEq.2CEq).20in.20the.20stdlib.html#231696271">(Mar 24 2021 at 19:39)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> Some kind of proposal document would be nice. Maybe an RFC isn't the right thing here, but a document or github issue explaining the situation, the problem, and your plan to fix/change things, would be great. Then we have something concrete to discuss and give an opinion on.</p>



<a name="231696450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/derive%28PartialEq%2CEq%29%20in%20the%20stdlib/near/231696450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/derive(PartialEq.2CEq).20in.20the.20stdlib.html#231696450">(Mar 24 2021 at 19:40)</a>:</h4>
<p>replacing them all with manual implementations doesn't sound great though. maybe the problem can be fixed in some other way. but it's definitely a problem we should discuss</p>



<a name="231706149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/derive%28PartialEq%2CEq%29%20in%20the%20stdlib/near/231706149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/derive(PartialEq.2CEq).20in.20the.20stdlib.html#231706149">(Mar 24 2021 at 20:50)</a>:</h4>
<p>Indeed, repetative structural impls would not be great. It could possibly be fixed by an unstable derive macro (is that possible), or a declmacro that does it the same way as the derive (but without the extra Structrual{Partial,}Eq impls).<br>
I can certainly file an issue on Github if that's the way to go.</p>



<a name="237072050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/derive%28PartialEq%2CEq%29%20in%20the%20stdlib/near/237072050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/derive(PartialEq.2CEq).20in.20the.20stdlib.html#237072050">(May 02 2021 at 18:35)</a>:</h4>
<p>I opened an issue for this: <a href="https://github.com/rust-lang/rust/issues/84391">https://github.com/rust-lang/rust/issues/84391</a>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>